home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / tpa2_a.arc / DEMONEW.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-28  |  6KB  |  185 lines

  1. {═══════════════════════════════ DEMONEW.PAS ═══════════════════════════════}
  2. { ─────────────  TP&Asm Release 2 new features demonstration  ───────────── }
  3. {═══════════════════════════════════════════════════════════════════════════}
  4. Uses DOS,ASMWATCH;
  5.  
  6. (* 
  7. ════════════════════════  Watches  ═════════════════════════
  8.       Place Cursor in column 1, Hit <Ctrl><F7>, and
  9.       Cursor right to get entire Watch Expression.
  10.  
  11. CPU.CsIp,p       - Segment:Offset of the current instruction
  12. CPU.CsIp^,m      - Hex Dump beginning at current instruction
  13. CPU.Flags-On     - Current state of CPU Flags
  14. CPU.SsSp,P       - Segment:Offset of the Stack Pointer
  15. W(CPU.SsSp^),$   - Memory Dump at current Stack Pointer
  16. CPU,$R           - Lists all register names and contents
  17.  
  18. ════════════ Type Definitions from ASMWATCH.TPU ════════════
  19.         (The variable CPU above is of type CPUType)
  20.  
  21. TYPE FgBits = (C,X1,P,X3,A,x5,Z,S,T,I,D,O,X12,X13,X14,X15);
  22. Const On = [X1,X3,X5,X12..X15];
  23. TYPE W = ARRAY[0..32] OF WORD;
  24.  
  25. TYPE CPUType = RECORD
  26.  Case Integer OF
  27.   1: (Ax,Bx,Cx,Dx,Bp,Si,Di,Ds,Es,Ip,Cs,Fg,Sp,Ss :Word);
  28.   2: (Al,Ah,Bl,Bh,Cl,Ch,Dl,Dh : Byte);
  29.   3: (dum18 :Array[1..18] of byte;
  30.       CsIp : Pointer;
  31.       Flags : Set of FgBits;
  32.       SsSp : Pointer;);
  33. END;
  34.  
  35. ════════════════════════════════════════════════════════════
  36. *)
  37.  
  38.  
  39. VAR TestW:Word;
  40.  
  41. {═══  The following Assembly Directive illustrates the "Asm" Statement   ═══}
  42. Procedure NearRet; Asm Ret;
  43.  
  44. Procedure First;
  45. BEGIN  {First Executable Statement of Procedure First}
  46. {╔══  The following illustrates the ability to allocate and use "Local"  ══╗}
  47. {╚══  CSeg Data in the first TRUE Procedure or Function.                 ══╝}
  48. Assemble
  49. Stc
  50. Jmp Start
  51. Dat Dw 1,2,3            ; FIRST Procedure can allocate and use CSeg Data.
  52. Start: IF C Mov Ax,Dat  ; Ax <-- 1
  53. Cmc
  54. IF C Mov Ax,$CEDE       ; Ax will not change
  55. Dec Ax                  ; Ax <-- 0
  56. Here: IF Z Jmp There
  57. Mov Bx,Dat+2            ; This statement won't execute
  58. There:
  59. Mov Cx,Dat+4            ; Cx <-- 3
  60. End; {Assemble}
  61. END; {Procedure First;}
  62.  
  63. {$F+} Procedure FarProc;  BEGIN Writeln('FarProc'); END; {$F-}
  64.       Procedure NearProc; BEGIN Writeln('NearProc'); END;
  65.       Procedure FwdProc;  Forward;
  66.  
  67. Procedure TestProc;
  68. Procedure NestProc; BEGIN WriteLn('NestProc'); END;
  69. Procedure SubTest;
  70.  
  71. Label AsmLabel,PasLabel,PasForward,PastData;
  72.  
  73. BEGIN  {First Executable Statement of SubTest}
  74.  
  75. {═════════════  The following illustrates the "Asm" statement  ═════════════}
  76. Asm Call First;
  77.  
  78. Assembly
  79. ;╔══   The following Pascal statement pushes the parent procedure's Bp    ══╗
  80. ;║     before calling NestProc.  Observe the Bp on the stack (above the     ║
  81. ;║     Return Address) during NestProc and compare with the subsequent      ║
  82. ;╚══   Assembly Call:                                                     ══╝
  83.  Pas NestProc;
  84.  
  85. ;═══════  The following 2 assembly statements produce the same code:  ═══════
  86.  Push [Bp+4]    ;Push Parent Proc Bp as LAST 'Parameter'
  87.  Call NestProc;
  88.  
  89. ;═════════════  The next two statements have the same result:   ═════════════
  90.  Pas FwdProc;
  91.  Call FwdProc;
  92.  
  93. ;╔═════  You can call near Proc/Functions within this Unit, or Far     ═════╗
  94. ;╚═════  Proc/Functions within this or another Unit:                   ═════╝
  95.  Call NearProc
  96.  Call FarProc
  97.  Call DosVersion ;(Not available in version 4 DOS Unit)
  98.  Mov TestW,Ax    ;Put Function Result into TestW
  99.  
  100. ;══════  You can "Call" System Procedures using the "Pas" Statement:  ═══════
  101.  Pas WRITELN('This WRITE statement called from within an assembly block');
  102.  Pas WRITELN('The DOS Version is ',Lo(TestW),'.',Hi(TestW));
  103. END;
  104.  
  105. IF Testw = DosVersion THEN
  106.    WRITELN('This Pascal function call produced the same result');
  107.  
  108. {╔═══  Assembly labels which are defined in a "Label" statement can be  ═══╗}
  109. {╚═══  the target of a Pascal "Goto" statement:                         ═══╝}
  110. Goto AsmLabel;
  111. PasLabel:
  112.   Assemble
  113.     Xor Ax,Ax    ;First Executable Statement following PasLabel
  114. ;═════  The Ds Register can be modified and restored using "SEG Data"   ═════
  115.     Mov Ds,Ax               ; Ds <-- 0
  116.     Mov Dx,SEG Data         ; Dx <-- Program Data Segment
  117.     Mov Ds,Dx               ; Restore Ds
  118.   FarBack:
  119.     Mov TestW,Cx ;First Executable Statement following FarBack
  120.     Push Cx
  121. ;═════════  A Pascal Label can be the target of an Assembly "Call"  ═════════
  122.     Call PasForward
  123.     Pop Cx       ;Call to PasForward will Return here
  124.     Cmp Cx,2
  125. ;╔═════════  Observe the change in "CPU.CsIp,p" for the next two   ═════════╗
  126. ;╚═════════  jumps when Cx = 3                                     ═════════╝
  127.     jE ForwdFar  ; This forward jump requires 5 bytes
  128.     jB ForwdNear ; This forward jump requires 2 bytes
  129.     Mov Ax,$1234
  130.   ForwdNear:
  131.     Jmp PastData
  132.  
  133. ;══════  The following 140 bytes cannot be bridged with a short jump  ═══════
  134.     db 20 dup 0
  135.     db 20 dup 0
  136.     db 20 dup 0
  137.     db 20 dup 0
  138.     db 20 dup 0
  139.     db 20 dup 0
  140.     db 20 dup 0
  141.  
  142.   Pastdata:
  143. ;══════════════  Observe the Watch Expression "CPU.Flags-On"   ══════════════
  144.     Std
  145.     Cld
  146.     Stc
  147.     Clc
  148.   ForwdFar:
  149.     Cli
  150.     Sti
  151.     Loop FarBack
  152. ;════════  The preceding Loop builds a 7 byte instruction sequence   ════════
  153.  
  154.     Jmp Finish
  155.  
  156.   AsmLabel:
  157.     Call AsmProc
  158.     Jmp PasLabel
  159. ;═════════  A Pascal Label can be the target of an Assembly "Jmp"   ═════════
  160.  
  161.    AsmProc:
  162.      Mov Cx,3    ; Initialize Cx for the Loop
  163.      Ret
  164.  
  165.    Finish:
  166.   END;  {Assemble}
  167.   Exit;
  168.  
  169. PasForward:
  170.   WRITELN('This Pascal Label defines a callable "Procedure" terminated');
  171.   WRITELN('by the Inline/Assembly Directive "NearRet";  Counter = ',TestW);
  172.   NearRet;
  173.  
  174. End; {SubTest}
  175.  
  176. BEGIN
  177.   SubTest;
  178. End; {TestProc}
  179.  
  180. Procedure FwdProc; BEGIN WriteLn('FwdProc'); END;
  181.  
  182. BEGIN
  183.   TestProc;
  184. END.
  185.